<?php

namespace app\manystore\model;

use think\Model;


class CampusMallOrderRefund extends Model
{

    

    

    // 表名
    protected $name = 'campus_mall_order_refund';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'status_text',
        'after_sales_status_text',
        'create_time_text',
        'operate_time_text',
        'refund_time_text',
        'refund_type_text'
    ];
    

    
    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
    }

    public function getAfterSalesStatusList()
    {
        return ['1' => __('After_sales_status 1'), '2' => __('After_sales_status 2'), '3' => __('After_sales_status 3'), '4' => __('After_sales_status 4'), '5' => __('After_sales_status 5')];
    }

    public function getRefundTypeList()
    {
        return ['0' => __('Refund_type 0'), '2' => __('Refund_type 2'), '3' => __('Refund_type 3'), '1' => __('Refund_type 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAfterSalesStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['after_sales_status']) ? $data['after_sales_status'] : '');
        $list = $this->getAfterSalesStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getOperateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['operate_time']) ? $data['operate_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getRefundTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refund_time']) ? $data['refund_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getRefundTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refund_type']) ? $data['refund_type'] : '');
        $list = $this->getRefundTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setOperateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setRefundTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('User', 'mid', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function campusmallorder()
    {
        return $this->belongsTo('CampusMallOrder', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function campusmallordergoods()
    {
        return $this->belongsTo('CampusMallOrderGoods', 'order_goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
